package com.wtwd.campus.utils;

import java.util.Collections;
import java.util.List;

public class GeneralSequenceUtils {

    /**
     * 此处映射关系，利用数组下表，与元素之间的对应关系
     * @param sequenceList
     * @return
     */
    public static int generalSequence(List<Integer> sequenceList){
        Collections.sort(sequenceList);
        if (sequenceList != null && sequenceList.size() > 0) {
            Object[] seqArray = sequenceList.toArray();
            for(int i = 0; i < seqArray.length;i++){
                if((int)seqArray[i] > (i+1)){
                    return i+1;
                }
            }
        }
        return sequenceList.size() +1;
    }

    public static int generalSequence2(List<Integer> sequenceList,Integer type){
        Collections.sort(sequenceList);
        if (sequenceList!=null&&sequenceList.size()>0){
            Object[] seqArray = sequenceList.toArray();
            if (type.equals(1)){//如果亲情号首位数据不是4,说明1号位数据被删除,重新添加一号位数据
                if ((int)seqArray[0]!=4){
                    return 4;
                }
            }else if(type.equals(0)){//如果白名单的首位数据不是7，说明1号位白名单数据被删除,重新添加一号位数据
                if ((int)seqArray[0]!=7){
                    return 7;
                }
            }
            int flag=0;
            for (int i = 0; i < seqArray.length; i++) {
                flag=i+1;
                if (seqArray.length<=flag){
                  return (int)seqArray[i]+1;
                }else {
                    if (((int)seqArray[i]+1!=(int)seqArray[flag])){
                        return (int)seqArray[i]+1;
                    }
                }

            }

        }
        return sequenceList.size() +1;
}

}
